# initialization of libraries for general use
# be sure that the following packages are installed
#   dplyr
#   ggplot2
#   lme4
#   Matrix and matrixStats
#   readxl
#   tidyr and tidyverse
#   fitdistrplus
#   sjPlot
#   ggpubr
#   lmerTest
library(matrixStats)
library(lme4)
library(tidyverse)
library(readxl)
library(ggplot2)
library(fitdistrplus)
library(sjPlot)  #for plotting lmer and glmer mods
library(ggpubr)
library(lmerTest)
# linear mixed model statistics mean_ER
# load data
mean_ER <- read_excel("D:/Meta_AnaOutput_Graphs/Zhu 2022 GAD paper (combined p-WTs)/mean_ER.xlsx")
# filter out some data that shouldn't be included
mean_ER_values <- mean_ER %>%
filter(drug != 'altered contexts')
# compare with p-WT (baseline)
mean_ER_values$genotype <- factor(mean_ER_values$genotype, levels = c("p-WT", "a5-i-KO", 'a5-pyr-KO'))
# make sure you compare with saline baseline
mean_ER_values$drug <- factor(mean_ER_values$drug, levels = c("saline", "etomidate 2mg/kg", "etomidate 4mg/kg", "etomidate 6mg/kg", "etomidate 7mg/kg", "etomidate 8mg/kg"))
# test using LMEM & ANOVA
mean_ER_values.model= lmer (Session1_mean_ER ~ drug * genotype + (1|animal_ID) + (1|expt_date), data=mean_ER_values, REML=TRUE)
anova(
mean_ER_values.model,
type = c("III", "II", "I", "3", "2", "1"),
ddf = "Kenward-Roger")
# perform some plotting
par(mfrow=c(1,3))
mean_ER_values.model= lmer (Session1_mean_ER ~ drug * genotype + (1|animal_ID) + (1|expt_date), data=mean_ER_values, REML=TRUE)
plot(residuals(mean_ER_values.model),las=1, ylim=c(-1,1))
hist(residuals(mean_ER_values.model),las=1)
qqnorm(residuals(mean_ER_values.model),las=1)
qqline(residuals(mean_ER_values.model), col = "red", lwd=2)
summary(mean_ER_values.model)
sjPlot::plot_model(mean_ER_values.model, title = "mean_ER_values ~ drug * genotype + (1|animal_ID) + (1|expt_date)")
sjPlot:: tab_model(mean_ER_values.model, title = "mean_ER_values ~ drug * genotype + (1|animal_ID) + (1|expt_date)",
auto.label = TRUE, show.stat = TRUE, show.df = TRUE, show.se = TRUE)
# load data
mean_ER <- read_excel("D:/Meta_AnaOutput_Graphs/Zhu 2022 GAD paper (combined p-WTs)/mean_ER.xlsx")
# filter out some data that shouldn't be included
mean_ER_values <- mean_ER %>%
filter(drug != 'altered contexts')
# compare with p-WT (baseline)
mean_ER_values$genotype <- factor(mean_ER_values$genotype, levels = c("p-WT", "a5-i-KO", 'a5-pyr-KO'))
# make sure you compare with saline baseline
mean_ER_values$drug <- factor(mean_ER_values$drug, levels = c("saline", "etomidate 2mg/kg", "etomidate 4mg/kg", "etomidate 6mg/kg", "etomidate 7mg/kg", "etomidate 8mg/kg"))
View(mean_ER_values)
# filter out some data that shouldn't be included
mean_ER_values <- mean_ER %>%
filter(drug != 'altered contexts')
# compare with p-WT (baseline)
mean_ER_values$genotype <- factor(mean_ER_values$genotype, levels = c("p-WT", "a5-i-KO", 'a5-pyr-KO'))
# make sure you compare with saline baseline
mean_ER_values$drug <- factor(mean_ER_values$drug, levels = c("saline", "etomidate 2mg/kg", "etomidate 4mg/kg", "etomidate 6mg/kg", "etomidate 7mg/kg", "etomidate 8mg/kg"))
# test using LMEM & ANOVA
mean_ER_values.model= lmer (Session1_Mean_Event_Rate ~ drug * genotype + (1|animal_ID) + (1|expt_date), data=mean_ER_values, REML=TRUE)
anova(
mean_ER_values.model,
type = c("III", "II", "I", "3", "2", "1"),
ddf = "Kenward-Roger")
# perform some plotting
par(mfrow=c(1,3))
mean_ER_values.model= lmer (Session1_Mean_Event_Rate ~ drug * genotype + (1|animal_ID) + (1|expt_date), data=mean_ER_values, REML=TRUE)
plot(residuals(mean_ER_values.model),las=1, ylim=c(-1,1))
hist(residuals(mean_ER_values.model),las=1)
qqnorm(residuals(mean_ER_values.model),las=1)
qqline(residuals(mean_ER_values.model), col = "red", lwd=2)
summary(mean_ER_values.model)
sjPlot::plot_model(mean_ER_values.model, title = "mean_ER_values ~ drug * genotype + (1|animal_ID) + (1|expt_date)")
sjPlot:: tab_model(mean_ER_values.model, title = "mean_ER_values ~ drug * genotype + (1|animal_ID) + (1|expt_date)",
auto.label = TRUE, show.stat = TRUE, show.df = TRUE, show.se = TRUE)
